﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service4u2.Example.Services;
using System.Threading;

namespace Service4u2.Example
{
    class Program
    {
        static FlickrEchoService flickrService = new FlickrEchoService();

        static void Main(string[] args)
        {
            bool serviceDone = false;
            FlickrEchoResult result = null;

            // Handle our result.
            flickrService.GotResult += (s, e) =>
                {
                    result = e.Argument;
                    serviceDone = true;
                };
            // Handle an error.
            flickrService.GotError += (s, e) =>
                {
                    result = null;
                    serviceDone = true;
                };

            // Start our simple service.
            flickrService.StartFlickrEchoAsync();

            // Wait around til its finished.
            while (!serviceDone)
            {
                Thread.Sleep(400);
            }

            // display the result.
            if ( result != null )
            {
                Console.WriteLine("Success - {0}, {1}, {2}", result.api_key._content, result.format._content, result.stat);
            }
            else
            {
                Console.WriteLine("Failure");
            }

            // Pause so we can see the result.
            Console.WriteLine("Any Key to Quit");
            var blah = Console.ReadKey();
        }
    }
}
